package cn.damai.mine.lock.hash;

import java.util.HashSet;
import java.util.Set;

public class HashTestOveride {
	
	public int i;

	public int getI() {
		return i;
	}

	public void setI(int i) {
		this.i = i;
	}

	/*public static void main(String[] args) {

		HashTestOveride a = new HashTestOveride();
		a.setI(1);
		
		HashTestOveride b = new HashTestOveride();
		b.setI(1);
		
		Set<HashTestOveride> set = new HashSet<HashTestOveride>();
		set.add(a);
		set.add(b);
		
		System.out.println(a.hashCode() == b.hashCode());
		System.out.println(a.equals(b));
		System.out.println(set);
	}*/
	
	/*@Override
	public int hashCode() {
		return i % 10;
	}
	
	public static void main(String[] args) {

		HashTestOveride a = new HashTestOveride();
		a.setI(1);
		
		HashTestOveride b = new HashTestOveride();
		b.setI(1);
		
		Set<HashTestOveride> set = new HashSet<HashTestOveride>();
		set.add(a);
		set.add(b);
		
		System.out.println(a.hashCode() == b.hashCode());
		System.out.println(a.equals(b));
		System.out.println(set);
	}*/
	
	@Override
	public int hashCode() {
		return i % 10;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		
		if (obj == this) {
			return true;
		}
		
		if (obj instanceof HashTestOveride) {
			return true;
		}
		
		HashTestOveride ht = (HashTestOveride) obj;
		if (ht.getI() == this.getI()) {
			return true;
		}
		
		return false;
	}
	
	public static void main(String[] args) {

		HashTestOveride a = new HashTestOveride();
		a.setI(1);
		
		HashTestOveride b = new HashTestOveride();
		b.setI(1);
		
		Set<HashTestOveride> set = new HashSet<HashTestOveride>();
		set.add(a);
		set.add(b);
		
		System.out.println(a.hashCode() == b.hashCode());
		System.out.println(a.equals(b));
		System.out.println(set);
	}

}
